package cn.swenty.backstage.framework.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.swenty.backstage.framework.controller.core.Result;
import cn.swenty.backstage.framework.controller.enums.Error;
import cn.swenty.backstage.framework.controller.enums.Status;

@Controller
@RequestMapping("/error/")
public class ExceptionController extends BasicController{
	
	/** 
	 * 请求异常 
	 * @return 
	 * @throws Exception 
	 * String 
	 */  
	@RequestMapping(value = "404", produces = "text/html;charset=UTF-8")  
	@ResponseBody
	public Result error_404() {   
	     return Status.getErrorJson(Error.PAGE_LOSE);  
	}  
	/** 
	 * 服务器异常 
	 * @return 
	 * String 
	 */  
	@RequestMapping(value ="500", produces = "text/html;charset=UTF-8") 
	@ResponseBody
	public Result error_500() {   
		return Status.getErrorJson(Error.DEAL_ERROR);
	}
	
	/** 
	 * 服务器异常 
	 * @return 
	 * String 
	 */  
	@RequestMapping(value ="{code}", produces = "text/html;charset=UTF-8") 
	@ResponseBody
	public Result error(@PathVariable("code") String code) {
		String msg = getPara("msg");
		Error e =  Error.get(code);
		e.setDescribe(msg);
		return Status.getErrorJson(e);
	} 
	
}
